package com.boscloud.controller;

import com.boscloud.pojo.ProductionVerifyDate;
import com.boscloud.util.oConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.boscloud.service.ProductionVerifyDateService;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@CrossOrigin //允许跨域
@RestController
public class ProductionVerifyDateController {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    @Autowired
    private ProductionVerifyDateService ProductionVerifyDate;
    @PostMapping("/ProductionVerifyDate")//入库日期-获取选择入库日期对应数据
    public List<ProductionVerifyDate> getProductionVerifyDate(@RequestBody Map<String, Object> params) throws IOException, ParseException {
        String startDate = (String) params.get("warehousingdatebegin");
        String endDate = (String) params.get("warehousingdateend");
        if(oConvertUtils.isEmpty(endDate)){
            endDate = sdf.format(new Date());
        }else {
            endDate = endDate.replace("-","");
        }
        if(oConvertUtils.isEmpty(startDate)){
            Date dt=sdf.parse(endDate);
            Calendar rightNow = Calendar.getInstance();
            rightNow.setTime(dt);
            rightNow.add(Calendar.MONTH,-6);//近半年数据
            Date dt1=rightNow.getTime();
            startDate = sdf.format(dt1);
        }else{
            startDate = startDate.replace("-","");
        }
        params.put("warehousingdatebegin",startDate);
        params.put("warehousingdateend",endDate);
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("PORTID","ITMS012");//接口ID
        return ProductionVerifyDate.getProductionVerifyDate(params,headers);
    }
}
